<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>	
<%@ include file="/commons/global.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <%@ include file="/commons/basejs.jsp"%>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<br/>
<blockquote class="layui-elem-quote layui-quote-nm">
  <label class="layui-form-label">操作用户</label>
  <div class="layui-input-inline">
         <input class="layui-input"  id="loginName" autocomplete="off">
  </div>
  <div class="layui-btn-group demoTable">
        <button class="select-on layui-btn layui-btn-sm" data-type="select"> <i class="layui-icon">&#xe615;</i> </button>
        <button class="layui-btn layui-btn-sm layui-btn-warm" id="refresh" data-type="reload"> <i class="layui-icon">ဂ</i> </button>
  </div>
</blockquote>
<div class="layui-col-md12">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-normal delclass" data-type="del">
            <i class="layui-icon">&#xe640;</i>删除
        </button>    
    </div>
    </div>
<br/>
<div class="layui-col-md12">
<table id="logList" class="layui-hide" lay-filter="log"></table>
</div>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs delclass" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
</script>
<script>
    layui.use('table', function () {
        var table = layui.table;
        //方法级渲染ss
        table.render({
             id: 'logList',
             elem: '#logList',
             page: true,
             height: 'full-160',
             url: basePath+'/sysLog/dataGrid',
             cols: [[
                 {type:'checkbox'},
                {field: 'loginName', title: '操作人', width: '10%',
                 templet:  function(d){
                     return '<span style="color: red;">'+ d.loginName +'</span>'
                }},
                {field: 'optContent', title: '描述内容', width: '30%', sort: true},
                {field: 'clientIp', title: 'IP地址', width: '10%', sort: true},
                {field: 'createTime',title: '操作时间', width: '25%', sort: true },
                {field: 'text', title: '操作', width: '19%', toolbar: '#toolBar'}
            ]]
        });
        var $ = layui.$,
         active = {
            select: function () {
                var loginName = $('#loginName').val();
                table.reload('logList', {
                    where: { 
                        loginName: loginName
                    }
                });
            }
            , del: function () {
                var checkStatus = table.checkStatus('logList')
                        , data = checkStatus.data;
                if (data.length == 0) {
                    layer.msg('请选择要删除的数据', {icon: 5});
                    return false;
                }
                var ids = [];
                for (item in data) {
                    ids.push(data[item].id);
                }
                del(ids);
            }
            , reload: function () {
                $('#loginName').val('');
                table.reload('logList', {
                    where: {
                        loginName: null,
                    }
                });
            },
        };
        //监听工具条
        table.on('tool(log)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
           // alert(data.id);
            var s= data.id;
            del([s]);
            }
        });

      $(' .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    /**批量删除id*/
    function del(ids) {
        $.ajax({
            url: "del",
            type: "post",
            data: {ids: ids},
            dataType: "json",
            traditional: true,
            success: function (data) {
            if (data.success) {
                layer.msg(data.msg, {icon: 6});
                layui.table.reload('logList');
                }else{
                layer.msg(data.msg, {icon : 5});			
                }
            }
        });
    }
    
       
    layui.laytpl.toDateString = function (d, format) {
        var date = new Date(d || new Date())
                , ymd = [
            this.digit(date.getFullYear(), 4)
            , this.digit(date.getMonth() + 1)
            , this.digit(date.getDate())
        ]
                , hms = [
            this.digit(date.getHours())
            , this.digit(date.getMinutes())
            , this.digit(date.getSeconds())
        ];

        format = format || 'yyyy-MM-dd HH:mm:ss';

        return format.replace(/yyyy/g, ymd[0])
                .replace(/MM/g, ymd[1])
                .replace(/dd/g, ymd[2])
                .replace(/HH/g, hms[0])
                .replace(/mm/g, hms[1])
                .replace(/ss/g, hms[2]);
    };
     //数字前置补零
    layui.laytpl.digit = function (num, length, end) {
        var str = '';
        num = String(num);
        length = length || 2;
        for (var i = num.length; i < length; i++) {
            str += '0';
        }
        return num < Math.pow(10, length) ? str + (num | 0) : num;
    };
    
    document.onkeydown = function (e) { // 回车提交表单
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code == 13) {
            $(".select .select-on").click();
        }
    };
</script>
</body>

</html>
